package com.x.erp.json;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.x.framework.model.BaseObject;

public class JsonConvertUtil {
	public static <T extends JsonObject>T convertToJsonModel(BaseObject baseObject, Class<T> jsonClass){
		return JSON.parseObject(JSON.toJSONString(baseObject), jsonClass);
	}
	
	public static <T extends BaseObject> T convertToBaseObject(JsonObject jsonObject, Class<T> baseClass){
		return JSON.parseObject(JSON.toJSONString(jsonObject), baseClass);
	}

	public static <T extends BaseObject, K extends JsonObject> List<K> convertToJsonObject(List<T> baseObjectList, Class<K> jsonClass) {
		List<K> result = new ArrayList<K>();
		if(baseObjectList == null || baseObjectList.size() < 1){
			return result;
		}
		for(T baseObject : baseObjectList){
			result.add(convertToJsonModel(baseObject, jsonClass));
		}
		return result;
	}
}
